package main

import (
	"flag"
	"fmt"
	"os"
)

type stringList []string

func (l *stringList) String() string {
	return fmt.Sprintf("%s", *l)
}

func (l *stringList) Set(value string) error {
	*l = append(*l, value)
	return nil
}

var (
	connIP   string
	port     uint
	asyncMod bool
	sendCmds stringList
)

func init() {
	var printVersion bool
	flag.StringVar(&connIP, "i", "", "Target IP")
	flag.UintVar(&port, "p", 0, "Target Port")
	flag.BoolVar(&asyncMod, "a", false, "Using async mode")
	flag.Var(&sendCmds, "c", "The commands send to server.")
	flag.BoolVar(&printVersion, "v", false, "print version")
	flag.Parse()
	if printVersion {
		fmt.Println("ver 1.0.0.1")
		os.Exit(0)
	}
}

/*
在.vscode/launch.json中设置命令行参数：
"args": [
	"-i",
	"127.0.0.1",
	"-c",
	"CMD_A,CMD_B,CMD_C"
]
*/
func main() {
	fmt.Printf("args: %s %d %v %v\n", connIP, port, asyncMod, sendCmds)
	fmt.Println("Hello world!")
}
